\Rdversion{1.1}
\name{DateYMD}

\alias{DateYMD}

\alias{day}
\alias{month}
\alias{year}

\alias{day<-}
\alias{month<-}
\alias{year<-}

\alias{getWeekday}
\alias{getNthWeekday}
\alias{isNthWeekday}
\alias{getDateOfNthWeekday}
\alias{isEndOfMonth}
\alias{getEndOfMonth}
\alias{getLastDayOfMonth}
\alias{isLastFebruary}
\alias{isLastWeekday}
\alias{getLastWeekday}

\alias{monthlyDateSequence}

\title{Date Constructor and Date manipulation functions}

\description{
These functions are used to generate objects of class Date and to check specific properties of these objects. 


}
\usage{
DateYMD(Year,Month,Day)

day(Date)
month(Date)
year(Date)

day(Date) <- value
month(Date) <- value
year(Date) <- value

getWeekday(Date)
getNthWeekday(Date)
isNthWeekday(Date,Weekday,NthWeekday)
getDateOfNthWeekday(Year,Month,Weekday,NthWeekday)
isEndOfMonth(Date)
getEndOfMonth(Year,Month)
getLastDayOfMonth(Year,Month)
isLastFebruary(Date)
isLastWeekday(Date)
getLastWeekday(Year,Month,Weekday)

monthlyDateSequence(StartDate,EndDate,Frequency,Direction=1,overlapping=FALSE,keepEndOfMonth=TRUE,keepNthWeekday=FALSE,keepLastWeekday=FALSE)

}
\arguments{
\item{Year}{a numeric vector or scalar for the year e.g. \code{2009}}
\item{Month}{a numeric vector or scalar for the month e.g. \code{11}}
\item{Day}{a numeric vector or scalar for the day e.g. \code{30}}
\item{Date}{a vector or scalar of class Date e.g. \code{Sys.Date()+0:10}}
\item{value}{a numeric vector or scalar e.g. \code{1:10}}

\item{Weekday}{a numeric value between 0 and 6 for the Weekday, Sunday=0}
\item{NthWeekday}{a numeric value between 1 and 5 for the nTh Weekday of the month, first=1}
\item{StartDate}{an object of class Date e.g. \code{Sys.Date()}}
\item{EndDate}{an object of class Date e.g. \code{DateYMD(2030,11,30)}}
\item{Frequency}{a numeric value indicating the payment frequency (Annual = 1, Semiannual = 2,...), e.g. \code{2} }
\item{Direction}{either 1 or -1 depending on whether the sequence counts from the start date or the end date}
\item{overlapping}{either TRUE or FALSE depending on whether the sequence should include the first date after the end date or the last date before the start date}
\item{keepEndOfMonth}{either TRUE or FALSE depending on whether the sequence from date is at the end of a month and all sequence dates should exactly be at the end of the month}
\item{keepNthWeekday}{either TRUE or FALSE, e.g. used to produce a sequence for payments every third Friday each month}
\item{keepLastWeekday}{either TRUE or FALSE, e.g. used to produce a sequence for payments every last Tuesday each month}
 
}
%\details{
%%  ~~ If necessary, more details than the description above ~~
%}
\value{
The returned value is a vector or scalar of class Date
%%  ~Describe the value returned
%%  If it is a LIST, use
%%  \item{comp1 }{Description of 'comp1'}
%%  \item{comp2 }{Description of 'comp2'}
%% ...
}
%\references{
%% ~put references to the literature/web site here ~
%}
\author{
Roger Bergande \email{roger@bergande.ch}
}
%\note{
%%  ~~further notes~~
%}
\seealso{
\code{
	\link{FFT}
	\link{Weekdays}
	\link{Holidays}
	\link{Sys.Date}
	\link{as.Date}
	\link{strptime}
	\link{DateTimeClasses}
	}
}

\examples{
# Examples

# Example DateYMD construction
today <- Sys.Date()
Y <- year(today)
M <- month(today)
D <- day(today)
todayYMD <- DateYMD(Y,M,D)
today==todayYMD

# Example DateYMD construction
Year <- 2010
Month <- 1:12
Day <- 15
DateYMD(Year,Month,Day)

# Example getWeekday, getNthWeekday
Date <- DateYMD(2010,6,15)
year(Date) <- 2011:2012
getWeekday(Date)

Date <- Sys.Date()+0:30
getNthWeekday(Date)

# Example get third Friday
Date <- DateYMD(2010,1,1)+0:364
Weekday <- 5 # 5 = Friday
NthWeekday <- 3 # Third Friday
Date[isNthWeekday(Date,Weekday,NthWeekday)]

Year <- 2010
Month <- 1:12
getDateOfNthWeekday(Year,Month,Weekday,NthWeekday)

# Example end of month
isEndOfMonth(DateYMD(2012,2,28))
isEndOfMonth(DateYMD(2012,2,29))
Year <- 2012
Month <- 2
getEndOfMonth(Year,Month)
getLastDayOfMonth(Year,Month)
isLastFebruary(DateYMD(2012,2,29))

}
\keyword{chron}

